package com.bitter.controller;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bitter.annotation.AutoIde;
import com.bitter.utils.RedisUtils;

@RestController
public class BitterController {

	private AtomicInteger stockNum = new AtomicInteger(100);

	@Autowired
	private RedisUtils redisUtils;

	@GetMapping("/getToken")
	public String getToken() {
		String token = UUID.randomUUID().toString().substring(1, 9);
		redisUtils.set(token, "1");
		return token;
	}

	/**
	 * 提交页面
	 * 
	 * @return
	 */
	@GetMapping("/submit")
	@AutoIde(value = true)
	public String rushStockNum() {
		stockNum.decrementAndGet();
		return "success";
	}

	/**
	 * 查看num的值
	 *
	 * @return
	 */
	@GetMapping("/getStockNum")
	@AutoIde(value = true)
	public String getStockNum() {
		return String.valueOf(stockNum.get());
	}

}
